package com.fce.fcesystem.config;

import javax.annotation.Resource;

import com.fce.fcesystem.controller.IndexController;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import redis.clients.jedis.Jedis;

import java.util.Map;

@Component  //此类一定要交给spring管理
public class ConsumerRunner implements ApplicationRunner{

	private static final String redisIp = "127.0.0.1";
	private static final int redisPort = 6379;

	@Resource
	private RedisTemplate redisTemplate;

	@Override
	public void run(ApplicationArguments args) throws Exception{
		System.out.println("需要在springBoot项目从redis中加载货币");
		//建立Redis连接
		Jedis jedis = new Jedis(redisIp, redisPort);
		//从redis中获取货币Map
		Map<String,String> redisMap= jedis.hgetAll("currencyMap");

		redisMap.forEach((k, v) -> System.out.println(k + " ==> " + v));

		IndexController.currencyMap = redisMap;
	}
}
